package com.hqyj.web.servlet;

import com.hqyj.pojo.User;
import com.hqyj.service.UserService;
import com.hqyj.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author cz
 * 2021/8/11 16:10
 */
@WebServlet("/register.do")
public class UserRegisterServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String username = req.getParameter("regname");
        String password = req.getParameter("regpass");
        User user = new User(username,password);
        userService.registerUser(user);
        resp.sendRedirect("/index.jsp");
    }
}
